let create_tab str =  
    let tab = GPack.hbox () in
     ignore(GMisc.label ~text:str ~packing:tab#add ());
     tab

let calculRGB color = 
    let r = Gdk.Color.red color
    and g = Gdk.Color.green color
    and b = Gdk.Color.blue color in
    (r,g,b)
 
let printRGB color =
    let (r,g,b) = calculRGB color in
         List.iter (fun x -> print_endline (string_of_int x)) [r;g;b]


let addDialogOption _ = 
    let dialog = GWindow.dialog
      ~title:"Settings" () in
  
    let box = GPack.vbox  ~border_width:5 ~spacing:5
      ~packing:dialog#vbox#pack () in
  
    let noteBook = GPack.notebook
     ~homogeneous_tabs:true ~show_border:true
     ~show_tabs:true ~border_width:4
     ~packing:box#add () in
  
    let tabLabel1 = create_tab "Background Color" in
    let colorBox = GPack.vbox () in
    let colorselection = GMisc.color_selection ~packing:colorBox#add () in
    let hboxColor =GPack.hbox ~packing:colorBox#add () in
    let ok_buttonColor = GButton.button ~label:"Apply" ~packing:hboxColor#add () in
    let _ = ok_buttonColor#connect#clicked ~callback:
        begin
            fun () ->
            let (rb,gb,bb) = calculRGB colorselection#color in
            Settings.rBg := rb; Settings.gBg := gb; Settings.bBg := bb;
 	    Settings.writeSettings ();
            List.iter (fun txt -> txt#misc#modify_base [`NORMAL, `COLOR colorselection#color]) !Function._listText;
        end in  
    let quit_buttonColor = GButton.button ~label:"Quit" ~packing:hboxColor#add () in
    let _ = quit_buttonColor#connect#clicked ~callback:(fun () -> dialog#misc#hide ()) in

    let tabLabel2 = create_tab "Font" in
    let fontBox = GPack.vbox () in
    let fontselection = GMisc.font_selection ~packing:fontBox#add () in
    let hboxFont =GPack.hbox ~packing:fontBox#add () in
    let ok_buttonFont = GButton.button ~label:"Apply" ~packing:hboxFont#add () in
    let _ = ok_buttonFont#connect#clicked ~callback:
	begin
	    fun () ->
   	    let font = fontselection#font_name in
	    Settings._fontName := font;
	    Settings.writeSettings ();
   	    List.iter (fun txt -> txt#misc#modify_font_by_name font) !Function._listText;
	end in


    let tabLabel3 = create_tab "Foreground Color" in
    let fgBox = GPack.vbox () in
    let fgselection = GMisc.color_selection ~packing:fgBox#add () in
    let hboxFg =GPack.hbox ~packing:fgBox#add () in
    let ok_buttonFg = GButton.button ~label:"Apply" ~packing:hboxFg#add () in
    let _ = ok_buttonFg#connect#clicked ~callback:
        begin
            fun () -> 
 	    let (rf,gf,bf) = calculRGB fgselection#color in
            Settings.rFg := rf; Settings.gFg := gf; Settings.bFg := bf;
 	    Settings.writeSettings ();
            List.iter (fun txt -> txt#misc#modify_text [`NORMAL, `COLOR fgselection#color]) !Function._listText;
        end in  
    

    let _ =  noteBook#insert_page
     ~tab_label:tabLabel1#coerce colorBox#coerce in 
    let _ = noteBook#insert_page
     ~tab_label:tabLabel2#coerce fontBox#coerce in
    let _ = noteBook#insert_page
     ~tab_label:tabLabel3#coerce fgBox#coerce in
     ignore(dialog#run ());
    dialog#misc#hide ()

